package com.gable.exhibition.websocket;

import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by Lesson on 2018/2/27.
 */
public class WSClientManager {

    public static Set<WebSocketSession> setWSS = new HashSet<WebSocketSession>();


    public static void  sendMessage(String message) {
        try{
            TextMessage toWSMsg = new TextMessage(message);
            for(WebSocketSession ws : setWSS){
                if(ws.isOpen()){
                    ws.sendMessage(toWSMsg);
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
